package com.act.service.impl;

import com.act.dao.ICostDao;
import com.act.domain.Cost;
import com.act.dto.PagerDTO;
import com.act.service.api.ICostService;
import com.act.vo.PagerVo;

import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class CostServiceImpl implements ICostService{
	
	@Resource
	private ICostDao costDao;

	@Override
	public void add(Cost cost) {
		costDao.add(cost);
	}

	@Override
	public void delete(int id) {
		costDao.delete(id);
	}

	@Override
	public void update(Cost cost) {
		costDao.update(cost);
	}

	@Override
	public PagerVo<Map> getAllList(@Param("pagerDTO") PagerDTO pagerDTO) {
		int startIndex = pagerDTO.getStartIndex();
		int endIndex = pagerDTO.getEndIndex();
		
		List<Map> list = costDao.getAllList(startIndex, endIndex);
		int totalCounts = costDao.getCounts();
		PagerVo<Map> pagerVo = new PagerVo<>(pagerDTO.getPageIndex(),pagerDTO.getPageSize(),totalCounts,list);
		
		return pagerVo;
	}

	@Override
	public int getCounts() {
		return costDao.getCounts();
	}

}
